import java.util.Stack;

import javax.swing.ImageIcon;

/**
 * Class representing a deck of cards as a stack
 * @author Kat Winter
 */
@SuppressWarnings("serial") // serializable object not given a serial value
public class Deck extends Stack<Card> {
	
	/**
	 * Constructor creates a deck of Cards with matching image path
	 */
	public Deck() {
		
		for (Suit suit: Suit.values()) {
			for (Face face : Face.values()) {
				String cardImagePath = "resources/cards/" + face.toString() + suit.toString().charAt(0) + ".gif";
				this.add(new Card(face, suit, new ImageIcon(cardImagePath)));
			}
		}
	}
	
	/**
	 * Uses the Fisher Yates algorithm to shuffle this Deck
	 */
	public void shuffle() {
		
	    int tempIndexInDeck;
	    
	    for (int i = this.size() - 1; i >= 0; i--){ 
	    	
	    	// Math.random() returns a double between 0.0 and 1.0
	    	// Multiplying it by "i" ensures the card picked will be the "i" card or lower in the deck
	    	tempIndexInDeck = ((int) (i * Math.random())); 
	      
	    	if (tempIndexInDeck != i){
	    	  
	    		Card tempCard = this.get(i);
	    		this.set(i, this.get(tempIndexInDeck));
	    		this.set(tempIndexInDeck, tempCard);
	    	}
	    }
	}
}
